﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Product_Manage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetDrpDownValue();

        }
    }

    public void PopulateShangPinList()
    {
        //lvShangPin.DataSource = Product.GetAllByCondition(DongDong.Common.Misc.ConvertToInt(drpZhuFenLei.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpCiFenLei.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpFenLei.SelectedValue), DongDong.Common.Misc.ConvertToDouble(txtJiaGeFrom.Text), DongDong.Common.Misc.ConvertToDouble(txtJiaGeTo.Text), DongDong.Common.Misc.ConvertToDouble(txtSCJFrom.Text), DongDong.Common.Misc.ConvertToDouble(txtSCJTo.Text), DongDong.Common.Misc.ConvertToDouble(txtJiFenFrom.Text), DongDong.Common.Misc.ConvertToDouble(txtJiFenTo.Text), DongDong.Common.Misc.ConvertToInt(drpPinPai.SelectedValue), txtKey.Text, 0).ToList();
        //lvShangPin.DataBind();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvShangPin.Items.Count == 0)
            PopulateShangPinList();
    }
    protected void lvShangPin_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateShangPinList();
    }


    public void GetDrpDownValue()
    {
        //drpZhuFenLei.DataSource = Nava.GetAllByParentID(0).Where(row => row.Type == (int)Nava.type.购物).ToList();
        //drpZhuFenLei.DataValueField = "ID";
        //drpZhuFenLei.DataTextField = "Title";
        //drpZhuFenLei.DataBind();
        drpZhuFenLei.Items.Insert(0, new ListItem("请选择", "0"));
        drpCiFenLei.Items.Insert(0, new ListItem("请选择", "0"));
        drpFenLei.Items.Insert(0, new ListItem("请选择", "0"));

        //drpPinPai.DataSource = Brand.GetAll();
        //drpPinPai.DataValueField = "ID";
        //drpPinPai.DataTextField = "Title";
        //drpPinPai.DataBind();
        drpPinPai.Items.Insert(0, new ListItem("请选择", "0"));

    }
    protected void drpZhuFenLei_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpZhuFenLei.SelectedValue);
        drpCiFenLei.DataSource = Nava.GetAllByParentID(ParentID);
        drpCiFenLei.DataValueField = "ID";
        drpCiFenLei.DataTextField = "Title";
        drpCiFenLei.DataBind();
        drpCiFenLei.Items.Insert(0, new ListItem("请选择", "0"));
    }
    protected void drpCiFenLei_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpCiFenLei.SelectedValue);
        drpFenLei.DataSource = Nava.GetAllByParentID(ParentID);
        drpFenLei.DataValueField = "ID";
        drpFenLei.DataTextField = "Title";
        drpFenLei.DataBind();
        drpFenLei.Items.Insert(0, new ListItem("请选择", "0"));
    }
    protected void lvShangPin_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        //Product.Delete(DongDong.Common.Misc.ConvertToInt(lvShangPin.DataKeys[e.ItemIndex].Value));
        PopulateShangPinList();
    }

    public string ReturnName(object ParentID)
    {
        string Name = "暂无信息";
        Nava objNav = Nava.Get(DongDong.Common.Misc.ConvertToInt(ParentID));
        if (objNav != null)
        {
            Name = objNav.Title;
        }
        return Name;
    }

    public string ReturnPinPai(object PinPaiID)
    {
        string PinPaiName = "暂无品牌";
        //Brand objBrand = Brand.Get(DongDong.Common.Misc.ConvertToInt(PinPaiID));
        //if (objBrand != null)
        //{
        //    PinPaiName = objBrand.Title;
        //}
        return PinPaiName;
    }
    protected void btn_search_Click_Click(object sender, EventArgs e)
    {
        PopulateShangPinList();
    }
}